from kisp import *
import random
import sys
import os

class Load(KISP):
	Type = "Sensor"
	Name = "Load"
	Description = "Checks Load on Localhost"
	Arguments = ["15 Minute Avg Load Threshold"]
	Units = "Load"

	def Start(self,arguments):
		try:
			p = os.popen("cat /proc/loadavg")
			out = p.read().split(" ")
			if float(out[2]) < float(arguments[0]):
				return [0, out[2],""]
			else:
				return [1, out[2],""]	
		except:
			return [-1,0,"Plugin Failed: %s - %s" % (sys.exc_info()[0],sys.exc_info()[1])]
